/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = test_sqlserver.c                                   */
/*  NOTE      =                                                    */
/*  DATE      = 2016/04/05 by songbb                               */
/*******************************************************************/

#include <stdio.h>
#include <CUnit/Basic.h>

#include "apmtest_cunit.h"
#include "frcomm.h"
#include "frmem.h"
#include <sqlserver/config.h>
#include "sqlserver_common/t_sqlserver_comm.h"
#include "sqlserver_core/t_sqlserver_core.h"
#include "sqlserver_token/t_sqlserver_token.h"

#include <frservice_mng.h>

static Frmemstat_mng g_st_memstat_mng={0,FR_MEMSTAT_COUNT_MAX};
static pthread_rwlock_t  g_memstat_rwlock = PTHREAD_RWLOCK_INITIALIZER;
static Frmem_env g_st_mem_env = {&g_st_memstat_mng, &g_memstat_rwlock};

int main(int argc, char **argv)
{
    if (fr_slab_init(&g_st_mem_env, MODULE_NAME) == NULL)
        return FR_FAIL;

    apmtest_cunit_registry();

    FunType fun_suites[1024];
    memset(fun_suites, 0x00, sizeof(fun_suites));
    int i_suites_len = sizeof(fun_suites) / sizeof(FunType);
    int i_loop = 0;

    // 加载各个测试组件
    // sqlserver_comm
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_bigint_add);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_bigint_multi);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_get_token_lst);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_int_pow);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_slqserver_create_request);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_destroy_request);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_destroy_session);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_frbindata_destory);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_frdata_destory);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_frdata_free);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_free);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_binary);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_datetime);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_datetimes);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_dec);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_guid);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_times);
    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_utf8str);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_varbytes);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_get_varchar);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_init_response);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_list_free);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_parameter_free);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_parse_prelogin);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_tds_ver_get);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_type_info_parse);
//
//    // sqlserver_core
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_set_analysis_data);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_detect);
//
//    // sqlserver_token
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_add_altmetadata);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_add_metadata);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite__sqlserver_skip_partname);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_altmetadata_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_altrow_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_colinfo_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_colmetadata_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_done_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_doneinproc_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_doneproc_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_envchange_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_error_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_featureextack_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_info_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_loginack_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_nbcrow_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_offset_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_order_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_returnstatus_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_returnvalue_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_row_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_sessionstate_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_sspi_token);
//    apmtest_cunit_add_suites(fun_suites, i_suites_len, add_suite_sqlserver_tabname_token);

    for (;i_loop < i_suites_len; i_loop++)
    {
        if (fun_suites[i_loop] != NULL && fun_suites[i_loop]() != 0)
        {
            CU_cleanup_registry();
            return CU_get_error();
        }
    }

    apmtest_cunit_unregistry();

    fr_slab_destroy();

    return 0;
}
